package com.sui.bigdata.flink.sql.function.scalar;

import ch.hsr.geohash.GeoHash;
import org.apache.flink.table.functions.ScalarFunction;


public class GeoHashUDF extends ScalarFunction {
    public String eval(Double lon, Double lat, Integer length) {
        if (lon == null || lat == null) return null;
        String geoHashStr = null;
        try {
            GeoHash geoHash = GeoHash.withCharacterPrecision(lat, lon, length);
            geoHashStr = geoHash.toBase32();

        } catch (Exception e) {
            return geoHashStr;
        }
        return geoHashStr;
    }

    public static void main(String[] args) {
        GeoHashUDF aesDecrypt = new GeoHashUDF();
        System.out.println(aesDecrypt.eval(121.566813, 30.085535, 6));
        System.out.println(aesDecrypt.eval(121.566813, 30.085535, 12));
    }
}
